<template xmlns:v-on="http://www.w3.org/1999/xhtml">
  <div class="content">
     <!-- 头部 -->
    <div class="main-title">
      <ul>
        <li>
          <div @click="navBackClick(1)" class="main-title-left main-title-noSelect">
            首页
          </div>
          <div class="main-title-right">
            /
          </div>
        </li>
        <li>
          <div @click="navBackClick(1)" class="main-title-left main-title-noSelect">
            待面试
          </div>
          <div class="main-title-right">
            /
          </div>
        </li>
        <li>
          <div class="main-title-left main-title-select">
            发送offer
          </div>
          <div class="main-title-right">
            <!-- / -->
          </div>
        </li>
      </ul>
    </div>
    <div class="content-center" v-loading="offerLoading">
      <div class="main-list">
        <div class="list-two">
          <div class="list-two-list">
            <div>姓名</div>
            <div>
              {{nameVal}}  
            </div>
          </div>
          <div class="list-two-list">
            <div>岗位</div>
            <div>
                <select @change="selectTypesClick" v-model="postype">
                  <option v-for="(type,index) in postypes" v-bind:value="index" :key="index">{{type.name}}</option>
                </select>           
            </div>
          </div>
        </div>
        <div class="list-two">
          <div class="list-two-list">
            <div>手机号</div>
            <div>
              <input type="text" v-model="phoneVal">         
            </div>
          </div>
          <div class="list-two-list">
            <div>邮箱</div>
            <div>
              <input type="text" v-model="emailVal">               
            </div>
          </div>
        </div>
        <div class="list-two">
          <div class="list-two-list">
            <div>薪资</div>
            <div>
              <input type="text" v-model="moneyVal">             
            </div>
          </div>
          <div class="list-two-list">
            <div>到岗日期</div>
            <div>
               <el-date-picker format="yyyy-MM-dd HH:mm"  v-model="issueDate" type="datetime" placeholder="选择时间">
               </el-date-picker>                      
            </div>
          </div>
        </div>
        <div class="list-button">
          <div class="button-look" @click="lookClick">
            预览
            <!-- 下载 -->
          </div>
          <div class="button-save" @click="addClick">
            保存
          </div>
          <div class="button-cancel" @click="backClick">
            取消
          </div>
        </div>
      </div>
      <div :class="{showdel:isShowdel}" class="delPopup">
        <transition name="slide-fade">
          <div class="delContent">
            <v-mIntercept @ok="confirmClick" @canle="cancelClick" :name="titlename"></v-mIntercept>
          </div>
        </transition>
      </div>
      <div v-show="isShowLook" class="lookShow">
        <div class="main-lookShow">
          <div class="main-lookShow-top">
            <div>个人简历</div>
            <div @click="lookHideClick">X</div>
          </div>
          <div class="main-lookShow-bottom" v-show="updateOrLokkShow">
            <iframe :src='pdfurls' v-if="pdfurlsShow" width="100%" height="500" scrolling="no">
              您的浏览器不支持框架
            </iframe>
            <div class="main-lookShow-bottom-pdfImg" v-else>
              <img :src="pdfurls" alt="">
            </div>
          </div>
          <div class="main-lookShow-bottomNoLOk" v-show="!updateOrLokkShow">
              此简历暂不不支持预览，请点击下载查看
          </div>
          <div class="main-lookShow-button">
            <!--  @click="upLookClick" -->
            <a class="button-lookShow-save" :href="pdfurlsHref">下载</a>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapActions } from "vuex";
import mIntercept from "../module/mIntercept";
export default {
  components: {
    "v-mIntercept": mIntercept
  },
  data() {
    return {
      offerLoading: false,
      updateOrLokkShow: false,
      pdfurlsShow: false,
      isShowLook: false,
      pdfurlsHref: "",
      pdfurls: "",
      type: "0",
      types: [{ name: "全部标签" }, { name: "标签1" }],
      postype: "0",
      postypes: [],
      isShowdel: true,
      intercept: false,
      toPath: "",
      titlename: "劳动成果还未保存，是否退出？",
      invitationObj: {},
      upFileUrl: "",
      nameVal: "",
      phoneVal: "",
      emailVal: "",
      moneyVal: "",
      workYearVal: "",
      expectedSalaryVal: "",
      backgroundVal: "",
      issueDate: "",
      addObj: {}
    };
  },
  // 过滤
  filters: {
    timeFun: function(val) {
      var now = new Date(val);
      var year = now.getYear() - 100;
      var month = now.getMonth() + 1;
      month = month > 9 ? month : "0 " + month;
      var date = now.getDate();
      date = date > 9 ? date : "0 " + date;
      var hour = now.getHours();
      hour = hour > 9 ? hour : "0 " + hour;
      var minute = now.getMinutes();
      minute = minute > 9 ? minute : "0 " + minute;
      return (
        "20 " + year + "- " + month + "- " + date + " " + hour + ": " + minute
      );
    }
  },
  // 模块新建时
  created: function() {
    var self = this;
    self.invitationObj = JSON.parse(sessionStorage.getItem("allListObj"));
    self.channeltypes = JSON.parse(sessionStorage.getItem("sourcestr"));
    self.postypes = JSON.parse(sessionStorage.getItem("poststr"));
    self.nameVal = self.invitationObj.name;
    // self.workYearVal = self.invitationObj.workYear;
    // self.expectedSalaryVal = self.invitationObj.expectedSalary;
    // self.phoneVal = self.invitationObj.phone;
    // self.backgroundVal = self.invitationObj.background;
    // self.upFileUrl = self.invitationObj.file;
    // self.emailVal = self.invitationObj.email;
    self.postypes.forEach(function(ele, ind) {
      if (ele.value == self.invitationObj.position) {
        self.postype = ind;
      }
    });
  },
  // 计算属性
  mounted() {},
  // 事件处理
  methods: {
    lookHideClick() {
      this.isShowLook = false;
      this.isShowupdatemEessage = false;
      this.isShowfeedback = false;
      this.isShowupdatemEessage = false;
      this.isShowfeedback = false;
      this.pdfurlsShow = false;
    },
    upLookClick() {
      var self = this;
      window.open(self.invitationObj.file);
    },
    lookClick() {
      var self = this;
      if (self.invitationObj.file) {
        if (
          self.invitationObj.file.indexOf(".PNG") > -1 ||
          self.invitationObj.file.indexOf(".png") > -1 ||
          self.invitationObj.file.indexOf(".jpg") > -1
        ) {
          self.pdfurls = self.invitationObj.file;
          self.pdfurlsShow = false;
          self.isShowLook = true;
          self.updateOrLokkShow = true;
          self.pdfurlsHref = self.invitationObj.file;
        } else {
          self.pdfurlsHref = self.invitationObj.file;
          var fileStr = self.invitationObj.file;
          fileStr = fileStr.split("file/")[1];
          var fileUpdate = self.invitationObj.file;
          fileUpdate = fileUpdate.split("file/")[1].split(".")[1];
          self.isShowLook = true;
          if (fileUpdate == "doc") {
            self.updateOrLokkShow = false;
          } else {
            self.updateOrLokkShow = true;
            self
              .getuploaddocx2PdfPreviewer({
                name: fileStr
              })
              .then(data => {
                if (data.code == 200) {
                  self.pdfurls =
                    "/static/PDFShow/generic/web/viewer.html?file=" +
                    data.data.src;
                  this.pdfurlsShow = true;
                } else {
                  self.$message({
                    type: "info",
                    message: data.message
                  });
                }
              })
              .catch(msg => {
                this.$router.push({
                  path: "/login"
                });
                self.$message({
                  type: "info",
                  message: "服务器异常!"
                });
              });
          }
        }
      } else {
        self.$message({
          type: "info",
          message: "暂无简历!"
        });
      }
    },
    // 返回
    backClick() {
      this.$router.push({
        path: "/home/interview/await"
      });
    },
    // 保存
    addClick() {
      var self = this;
      var vFunFalse = self.vFun();
      self.addObj["position"] = self.postypes[self.postype].value;
      self.addObj["name"] = self.nameVal;
      self.addObj["id"] = self.$route.query.id;
      if (vFunFalse == true) {
        self.offerLoading = true;
        self
          .getinterviewsendOffer(self.addObj)
          .then(data => {
            self.offerLoading = false;
            if (data.code == 200) {
              self.$message({
                type: "success",
                message: "发送邮件成功!"
              });
              self.$router.push({
                path: "/home/interview/await"
              });
            } else {
              self.$message({
                type: "info",
                message: data.message
              });
            }
          })
          .catch(msg => {
            self.offerLoading = false;
            self.$message({
              type: "info",
              message: "服务器异常!"
            });
            this.$router.push({
              path: "/login"
            });
          });
      }
    },
    vFun() {
      var self = this;
      var phoneReg = new RegExp(/^\d{11}$/);
      var numReg = new RegExp(/^\d{1,7}$/);
      var num1Reg = new RegExp(/^\d{1,7}$/);
      var emailReg = new RegExp(
        /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
      );
      var strReg = new RegExp(/^[\u4e00-\u9fa5]{2,10}$/);
      var vFunFalse = false;
      if (
        numReg.test(self.moneyVal) == true &&
        emailReg.test(self.emailVal) == true &&
        phoneReg.test(self.phoneVal) == true
      ) {
        self.addObj["money"] = self.moneyVal;
        self.addObj["email"] = self.emailVal;
        self.addObj["phone"] = self.phoneVal;
        if (self.issueDate) {
          self.addObj["joinTimePlan"] = new Date(self.issueDate).getTime();
          vFunFalse = true;
        } else {
          self.$message({
            type: "info",
            message: "到岗日期必填"
          });
          vFunFalse = false;
          delete self.addObj.joinTimePlan;
        }
      } else {
        vFunFalse = false;
        if (phoneReg.test(self.phoneVal) == false) {
          self.$message({
            type: "info",
            message: "手机号项输入不正确"
          });
        } else if (emailReg.test(self.emailVal) == false) {
          self.$message({
            type: "info",
            message: "邮箱项输入不正确"
          });
        } else if (numReg.test(self.moneyVal) == false) {
          self.$message({
            type: "info",
            message: "薪资项必填且为数字"
          });
        }
      }

      return vFunFalse;
    },
    // 面包屑返回
    navBackClick(index) {
      if (index == 2) {
        this.$router.push({
          path: "/home/interview/await"
        });
      } else if (index == 1) {
        this.$router.push({
          path: "/home/interview/await"
        });
      }
    },
    selectTypesClick() {},
    confirmClick() {
      this.intercept = true;
      var url = this.toPath;
      this.$router.push({
        path: url
      });
    },
    //取消未保存弹出框
    cancelClick() {
      this.isShowdel = true;
    },
    ...mapActions(["getinterviewsendOffer", "getuploaddocx2PdfPreviewer"])
  },
  // 监视
  watch: {}
};
</script>
<style scoped>
.button-look {
  margin-left: 108px;
  width: 74px;
  height: 32px;
  border-radius: 4px;
  background-color: #fe966d;
  text-align: center;
  line-height: 32px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  color: rgba(255, 255, 255, 1);
}

.button-save {
  margin-left: 8px;
  width: 74px;
  height: 32px;
  border-radius: 4px;
  background-color: rgba(250, 140, 22, 1);
  text-align: center;
  line-height: 32px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  color: rgba(255, 255, 255, 1);
}
.button-cancel {
  cursor: pointer;
  margin-left: 8px;
  width: 74px;
  height: 32px;
  border: 1px solid #ffd9d9d9;
  text-align: center;
  line-height: 32px;
  font-size: 14px;
  border-radius: 4px;
  background-color: #fff;
  color: rgba(0, 0, 0, 0.65);
}
.list-button {
  margin-top: 45px;
  width: 500px;
  display: flex;
}
.list-file-r-file label {
  border-radius: 4px;
  min-width: 120px;
  height: 30px;
  background-color: #2fa89e;
  display: flex;
  align-items: center;
  justify-content: space-around;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
}
.list-file-r-file label img {
  width: 20px;
  height: 20px;
}
.list-file-r-file input {
  opacity: 0;
}
.list-file-r-file {
  min-width: 110px;
  height: 28px;
  margin-left: 25px;
  display: flex;
}
.list-file-r-img {
  width: 110px;
  height: 50px;
  border: 1px solid #ccc;
}
.list-file-right {
  width: 500px;
  height: 50px;
  margin-left: 15px;
  display: flex;
  align-items: center;
}
.list-file {
  display: flex;
  height: 70px;
  margin-top: 18px;
  width: 100%;
}

.list-file > div:nth-child(1) {
  width: 150px;
  font-size: 15px;
  font-weight: 600;
  color: #666;
  text-align: right;
}
.list-text {
  display: flex;
  min-height: 32px;
  width: 100%;
  margin-top: 35px;
}

.list-text > div:nth-child(1) {
  width: 93px;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  text-align: right;
}
.list-text > div:nth-child(2) textarea {
  width: 80%;
  resize: none;
  height: 129px;
  border: 1px solid #ffd7d7d7;
  border-radius: 4px;
  color: rgba(0, 0, 0, 0.65);
  font-size: 14px;
  padding-top: 7px;
  padding-left: 7px;
}
.list-text > div:nth-child(2) {
  margin-left: 15px;
  width: calc(100% - 110px);
  min-height: 32px;
  color: rgba(0, 0, 0, 0.65);
  font-size: 14px;
}
.list-two-two {
  height: 32px;
  width: 100%;
  display: flex;
  align-items: center;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
}
.list-two-two > div:nth-child(1) {
  width: 93px;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  text-align: right;
}
.list-two-two > div:nth-child(2) {
  margin-left: 15px;
}
.list-two-list {
  display: flex;
  width: 50%;
  align-items: center;
}
.list-two-list > div:nth-child(1) {
  width: 93px;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  text-align: right;
}
.list-two-list > div:nth-child(2) {
  margin-left: 15px;
  width: calc(100% - 118px);
  /* border: 1px solid red; */
  color: rgba(0, 0, 0, 0.65);
  font-size: 14px;
}
.list-two-list > div:nth-child(2) input {
  width: 94%;
}
.list-two-list > div:nth-child(2) select {
  width: calc(94% + 7px);
}
.list-two > div:nth-child(2) {
  margin-left: 15px;
}

.list-two {
  display: flex;
  align-items: center;
  height: 32px;
  margin-top: 35px;
}

select {
  width: 207px;
  height: 32px;
  border-radius: 4px;
  line-height: 32px;
  color: rgba(0, 0, 0, 0.65);
  border: 1px solid #ffd7d7d7;
  padding-left: 3px;
  font-size: 14px;
}
input {
  width: 200px;
  height: 32px;
  border-radius: 4px;
  line-height: 32px;
  color: rgba(0, 0, 0, 0.65);
  border: 1px solid #ffd7d7d7;
  padding-left: 7px;
  font-size: 14px;
}
select::-ms-expand,
select::-webkit-expand {
  display: none;
}
.main-list > div {
  width: 100%;
  min-height: 32px;
}
.main-list {
  width: 100%;
  margin-top: 15px;
  min-height: 50px;
  background-color: #ffff;
  min-height: 500px;
}

.main-title-noSelect {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
  cursor: pointer;
}
.main-title-select {
  font-size: 14px;
  color: rgba(0, 0, 0, 0.85);
  font-weight: 600;
}

.main-title-right {
  width: 23px;
  text-align: center;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
}

.main-title ul {
  width: 100%;
  display: flex;
  height: 54px;
  margin-left: 34px;
}
.main-title ul li {
  display: flex;
}
.main-title {
  width: 100%;
  height: 54px;
  background-color: #fff;
  line-height: 54px;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: inset 0px 3px 3px 0px #ccc;
}
.content {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: rgba(240, 242, 245, 1) !important;
  min-height: 720px;
  /* border: 1px solid red; */
  display: flex;
  flex-wrap: wrap;
}

.content-center {
  overflow: hidden;
  width: calc(100% - 48px);
  margin-left: 24px;
  background-color: #fff;
  margin-top: 24px;
  border-radius: 3px;
  min-height: calc(100% - 78px - 24px);
  margin-bottom: 24px;
}

/*取消弹出框*/

.delPopup {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0);
  z-index: 1000000;
}

.showdel {
  display: none;
}

.button-lookShow-save {
  width: 74px;
  height: 32px;
  border-radius: 4px;
  background-color: rgba(250, 140, 22, 1);
  text-align: center;
  line-height: 32px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  color: rgba(255, 255, 255, 1);
}

.main-lookShow-button {
  height: 55px;
  display: flex;
  width: 100%;
  margin-top: 25px;
  align-items: center;
  justify-content: center;
}
.main-lookShow-bottomNoLOk {
  width: 90%;
  margin: 0 auto;
  margin-top: 36px;
  height: 500px;
  border: 1px solid #ccc;
  line-height: 500px;
  font-size: 20px;
  color: #ccc;
  text-align: center;
}
.main-lookShow-bottom .main-lookShow-bottom-pdfImg {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: scroll;
}
.main-lookShow-bottom img {
  width: 100%;
}
.main-lookShow-bottom {
  width: 90%;
  margin: 0 auto;
  margin-top: 36px;
  height: 500px;
  border: 1px solid #ccc;
}

.main-lookShow-top > div:nth-child(1) {
  font-size: 16px;
  font-weight: 600;
  color: #5c5c5c;
  margin-left: 30px;
  font-size: 20px;
  color: rgba(0, 0, 0, 1);
}

.main-lookShow-top > div:nth-child(2) {
  margin-right: 20px;
  width: 35px;
  height: 35px;
  text-align: center;
  line-height: 35px;
  border: 1px solid #ccc;
  border-radius: 50%;
  cursor: pointer;
  color: #ccc;
}

.main-lookShow-top {
  display: flex;
  justify-content: space-between;
  height: 22px;
  margin-top: 30px;
  align-items: center;
}

.main-lookShow {
  width: 900px;
  height: 700px;
  background-color: #fff;
  border-radius: 5px;
}

.lookShow {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  background-color: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.delContent {
  width: 525px;
  height: 280px;
  background-color: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0px 10px 10px #eaeaea;
  border-radius: 7px;
  margin: calc((100vh - 280px) / 2) auto;
  z-index: 100000;
}

.slide-fade-enter-active {
  transition: all 0.7s ease;
}

.slide-fade-enter,
.slide-fade-leave-active {
  transform: translateY(-30px);
  opacity: 0;
}
</style>